//
//  BaseWebView.swift
//  AliBaiChuan
//
//  Created by 郑东喜 on 2017/2/21.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit

class BaseWebView: UIViewController {

    // MARK:- base webView
    lazy var weView: UIWebView = {
        
        let rect : CGRect = CGRect.init(x: 0, y: 0, width:SW, height: SH)
        let web : UIWebView = UIWebView.init(frame: rect)
        web.delegate = self
        return web
    }()
    

    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        print("\((#file as NSString).lastPathComponent):(\(#line))\n",self.navigationController?.childViewControllers.count as Any)

    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        
        print("\((#file as NSString).lastPathComponent):(\(#line))\n")
        
        
    }
    
    ///url
    var url : String = ""
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        //添加网页
        view.addSubview(weView)
    }
}

// MARK:- UIWebViewDelegate
extension BaseWebView : UIWebViewDelegate {
    func webViewDidStartLoad(_ webView: UIWebView) {
//        MBManager.showLoading()
        Animated.vcWithTransiton(_view: self.weView, animatedType: "kCATransitionFade", timeduration: 1)

    }
    
    func webViewDidFinishLoad(_ webView: UIWebView) {
        
//        MBManager.hideAlert()
        
        self.title = webView.stringByEvaluatingJavaScript(from: "document.title")

    }
}

